package objday03;

import java.util.Scanner;

public class AtmAction {
    private static Scanner scanner;
    static {
        scanner = new Scanner(System.in);
    }
    private static String name;
    private  static String choose;
    public static void run(User[] users){
       lin: while (true){
            System.out.println("欢迎管理员登录");
            System.out.println("请选择你要办理的业务");
            System.out.println("1.查看所有用户");
            System.out.println("2.查看需要被激活用户列表");
            System.out.println("3.激活用户");
            System.out.println("4.冻结用户");
            System.out.println("5.退出");
            choose = scanner.next();
           switch (choose){
               case "1":
                   System.out.println("用户   \t"+"是否激活   \t"+"卡号  \t"+"余额  \t");

                   for (User user : users) {
                       if("admin".equals(user.getUserName())){
                           continue;
                       }
                       Customer customer = (Customer)user;
                       System.out.println(customer.getUserName()+"\t"+customer.isActive+"\t"+customer.card+"\t"+customer.getMoney());
                   }
                   break;
               case "2":
                   System.out.println("用户   \t"+"是否激活   \t"+"卡号  \t"+"余额  \t");
                   for (User user : users) {
                       if("admin".equals(user.getUserName())){
                           continue;
                       }
                       Customer customer = (Customer) user;
                       if (!customer.isActive){
                           System.out.println(customer.getUserName()+"\t"+customer.isActive+"\t"+customer.card+"\t"+customer.getMoney());
                       }

                   }
                   break;
               case "3":
                   System.out.println("用户   \t"+"是否激活 \t"+"卡号  \t"+"余额  \t");
                   for (User user : users) {
                       if("admin".equals(user.getUserName())){
                           continue;
                       }
                       Customer customer = (Customer) user;
                       if (!customer.isActive){
                           System.out.println(customer.getUserName()+"\t"+customer.isActive+"\t"+customer.card+"\t"+customer.getMoney());
                       }

                   }
                   System.out.println("请输入你要激活的账户");
                   name = scanner.next();
                   for (User user : users) {

                       if(name.equals(user.getUserName())){
                           if(!user.isActive){
                               user.isActive = true;
                               System.out.println("激活成功");

                           }
                       }
                   }
                   break;

               case "4":
                   System.out.println("用户   \t"+"是否激活 \t"+"卡号  \t"+"余额  \t");

                   for (User user : users) {
                       if("admin".equals(user.getUserName())){
                           continue;
                       }
                       Customer customer = (Customer)user;
                       System.out.println(customer.getUserName()+"\t"+customer.isActive+"\t"+customer.card+"\t"+customer.getMoney());
                   }
                   System.out.println("请选择你要冻结的账户");
                   name = scanner.next();
                   for (User user : users) {

                       if(name.equals(user.getUserName())){
                           if(user.isActive){
                               user.isActive = false;
                               System.out.println("冻结成功");

                           }
                       }
                   }
                   break;
               case "5":
                   System.out.println("欢迎下次光临");
                   break lin;
               default:
                   System.out.println("输入错误，请重新输入");
                   break;

           }
        }

    }

}
